package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.SystemMessages;
import cn.wolfcode.trip.base.query.SystemMessagesQueryObject;
import cn.wolfcode.trip.base.service.ISystemMessagesService;
import cn.wolfcode.trip.base.service.IUserService;
import cn.wolfcode.trip.base.utils.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/systemmessages")
public class SystemMessagesController {

    @Autowired
    private ISystemMessagesService systemMessagesService;

    //系统列表
    @GetMapping("/{userId}")
    @ResponseBody
    public Object list(@ModelAttribute("qo")SystemMessagesQueryObject qo){
        qo.setOrderBy("sm.createTime desc");
        return  systemMessagesService.query(qo);

    }
    @PutMapping("/{userId}/updateAllState")
    @ResponseBody
    public Object updateAllState(@PathVariable Long userId){
        JSONResult result = new JSONResult();
        try {
            systemMessagesService.updateAllState(userId);
        } catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }


}
